package service

import (
	"github.com/garyburd/redigo/redis"
	"sync"
	"time"
)

const (
	ProductStatusNormal       = 0
	ProductStatusSaleOut      = 1
	ProductStatusForceSaleOut = 2
)

type SecProductInfoConf struct {
	ProductId int
	StartTime int64
	EndTime   int64
	Status    int
	Total     int
	Left      int
}
type RedisConf struct {
	Addr        string
	MaxIdle     int
	MaxActive   int
	IdleTimeout int
}
type EtcdConf struct {
	Addr          string
	TimeOut       int
	SecKeyPrefix  string
	SecProductKey string
}

type SecKillConf struct {
	RedisBlackConf               RedisConf
	RedisProxy2LayerConf         RedisConf
	EtcdConf                     EtcdConf
	LogPath                      string
	LogLevel                     string
	SecProductInfoMap            map[int]*SecProductInfoConf
	RwSecProductLock             sync.RWMutex
	CookieSecretKey              string
	UserSecAccessLimit           int
	ReferWhiteList               []string
	IPSecAccessLimit             int
	IpBlackMap                   map[string]bool
	IdBlackMap                   map[int]bool
	BlackRedisPool               *redis.Pool
	Proxy2LayerRedisPool         *redis.Pool
	RWBlackLock                  sync.Mutex
	secLimitMgr                  *SecLimitMgr
	WriteProxy2LayerGoroutineNum int
	ReadLayer2ProxyGoroutineNum  int

	SecReqChan     chan *SecRequest
	SecReqChanSize int
}

type SecRequest struct {
	ProductId     int
	Source        string
	AuthCode      string
	SecTime       string
	Nance         string
	UserId        int
	UserAuthSign  string
	AccessTime    time.Time
	ClientAddr    string
	ClientReferer string
}
